package org.birrap.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;


@Entity
@Table(name = "BARES_USUARIO_T")
@XmlRootElement
@NamedQueries({

    @NamedQuery(name = "BaresUsuarioT.findAll", query = "SELECT b FROM BaresUsuarioT b"),
    @NamedQuery(name = "BaresUsuarioT.findByIdBarSiesDueno", query = "SELECT b FROM BaresUsuarioT b WHERE b.baresUsuarioTPK.idBar = :idBar AND b.dueno ='Y'"),
    @NamedQuery(name = "BaresUsuarioT.findByCorreo", query = "SELECT b FROM BaresUsuarioT b WHERE b.baresUsuarioTPK.correo = :correo"),
    @NamedQuery(name = "BaresUsuarioT.findByDueno", query = "SELECT b FROM BaresUsuarioT b WHERE b.dueno = :dueno"),
    @NamedQuery(name = "BaresUsuarioT.findByIdBarAndCorreo",query = "SELECT b FROM BaresUsuarioT b WHERE b.baresUsuarioTPK = :baresUsuarioTPK"),
    @NamedQuery(name = "BaresUsuarioT.findBaresTUltimosubidobyDueno", query = "SELECT MAX(b.baresUsuarioTPK.idBar) from BaresUsuarioT b WHERE b.baresUsuarioTPK.correo = :correo"),
    @NamedQuery(name = "BaresUsuarioT.findByCorreoYFavorito",query = "SELECT b FROM BaresUsuarioT b WHERE b.baresUsuarioTPK.correo = :correo and b.dueno = 'N' "),
    @NamedQuery(name = "BaresUsuarioT.removeByBaresUsuarioTPK",query = "DELETE FROM BaresUsuarioT b WHERE b.baresUsuarioTPK = :baresUsuarioTPK"),
    @NamedQuery(name = "BaresUsuarioT.findByCorreoYDueno",query = "SELECT b FROM BaresUsuarioT b WHERE b.baresUsuarioTPK.correo = :correo AND b.dueno = 'Y'"),
    @NamedQuery(name = "BaresUsuarioT.findByIdBarAndCorreoAndDueno",query = "SELECT b FROM BaresUsuarioT b WHERE b.baresUsuarioTPK = :baresUsuarioTPK AND b.dueno = 'Y'")})



public class BaresUsuarioT implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @EmbeddedId
    protected BaresUsuarioTPK baresUsuarioTPK;
    
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 1)
    @Column(name = "DUENO")
    private String dueno;
    
    @JoinColumn(name = "CORREO", referencedColumnName = "CORREO", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private UsuariosT usuariosT;
    
    @JoinColumn(name = "ID_BAR", referencedColumnName = "ID_BAR", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private BaresT baresT;

    public BaresUsuarioT() {
    }

    public BaresUsuarioT(BaresUsuarioTPK baresUsuarioTPK) {
        this.baresUsuarioTPK = baresUsuarioTPK;
    }

    public BaresUsuarioT(BaresUsuarioTPK baresUsuarioTPK, String dueno) {
        this.baresUsuarioTPK = baresUsuarioTPK;
        this.dueno = dueno;
    }

    public BaresUsuarioT(int idBar, String correo) {
        this.baresUsuarioTPK = new BaresUsuarioTPK(idBar, correo);
    }

    public BaresUsuarioTPK getBaresUsuarioTPK() {
        return baresUsuarioTPK;
    }

    public void setBaresUsuarioTPK(BaresUsuarioTPK baresUsuarioTPK) {
        this.baresUsuarioTPK = baresUsuarioTPK;
    }

    public String getDueno() {
        return dueno;
    }

    public void setDueno(String dueno) {
        this.dueno = dueno;
    }

    public UsuariosT getUsuariosT() {
        return usuariosT;
    }

    public void setUsuariosT(UsuariosT usuariosT) {
        this.usuariosT = usuariosT;
    }

    public BaresT getBaresT() {
        return baresT;
    }

    public void setBaresT(BaresT baresT) {
        this.baresT = baresT;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (baresUsuarioTPK != null ? baresUsuarioTPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof BaresUsuarioT)) {
            return false;
        }
        BaresUsuarioT other = (BaresUsuarioT) object;
        if ((this.baresUsuarioTPK == null && other.baresUsuarioTPK != null) || (this.baresUsuarioTPK != null && !this.baresUsuarioTPK.equals(other.baresUsuarioTPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.birrap.entities.BaresUsuarioT[ baresUsuarioTPK=" + baresUsuarioTPK + " ]";
    }
    
}
